package main

import (
	"github.com/go-ole/go-ole"
	"github.com/go-ole/go-ole/oleutil"
)

func tts(text string) {
	// 在当前goroutine中初始化COM库
	err = ole.CoInitialize(0)
	ifErr(err)
	defer ole.CoUninitialize()

	// 创建SAPI语音对象
	unknown, err := oleutil.CreateObject("SAPI.SpVoice")
	if err != nil {
		return // 静默失败，避免panic
	}
	defer unknown.Release()

	// 获取IDispatch接口
	voice, err := unknown.QueryInterface(ole.IID_IDispatch)
	if err != nil {
		return // 静默失败，避免panic
	}
	defer voice.Release()

	// 调用Speak方法
	_, err = oleutil.CallMethod(voice, "Speak", text)
	if err != nil {
		return // 静默失败，避免panic
	}
}
